package com.ele.service.impl;


import com.ele.dao.BusinessDao;
import com.ele.dao.impl.BusinessDaoImpl;
import com.ele.pojo.Business;
import com.ele.pojo.PageResult;
import com.ele.service.BusinessService;

import java.util.List;

public class BusinessServiceImpl implements BusinessService {
    private BusinessDao businessDao = new BusinessDaoImpl();
    @Override
    public Integer BusinessRegister(Business business) {
        try {
            return this.businessDao.BusinessRegister(business);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Business businessLogin(String account, String password) {
        try {
            return this.businessDao.businessLogin(account,password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Integer businessUpdate(Business business) {
        try {
            return this.businessDao.businessUpdate(business);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Integer businessDelete(String id) {
        try {
            return this.businessDao.businessDelete(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public PageResult<List<Business>> findAll(String account , String contact, String telephone, String currentPage, String pageSize ) {
        try{
            // 分页和条件查询数据
            List<Business> list =  this.businessDao.findAll(account,contact,telephone,currentPage,pageSize);
            // 需要查询数据库的总记录数
            Long total = this.businessDao.selectCount();
            // 手动创建一个用于封装分页结果集的对象
            PageResult<List<Business>> pageResult = new PageResult<List<Business>>();
            // 手动给分页结果集的对象上设置参数 ， 分页查询出来当前页面需要显示的数据
            pageResult.setDatas(list);
            // 手动给分页结果集的对象上设置参数 ， 数据表的总记录数
            pageResult.setTotal(total);
            return pageResult;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
